#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
const int maxn = 610, maxm = 2e6 + 10;
int sz;
int n, m, k, a[maxm], emp, sp, cnt[maxn];
int bel[maxn];
queue<int> qu;
bool inq[maxn];
struct Satck{
    deque<int> q;
    int id;
    bool empty(){return q.empty();}
    int size(){return q.size();}
    void push_back(int x){
        cnt[x] ^= 1;
        if(!q.empty() && q.back() == x) q.ppb(), sz--;
        else q.pb(x), sz++;
        if(q.size() < 2 && !inq[id]) qu.push(id), inq[id] = 1;
    }
    void pop_front(){
        cnt[front()] ^= 1, q.pop_front(), sz--;
        if(q.size() < 2 && !inq[id]) qu.push(id), inq[id] = 1;
    }
    int back(){assert(!q.empty()); return q.back();}
    int front(){assert(!q.empty()); return q.front();}
}st[maxn];
int front(){
    while(!qu.empty() && (st[qu.front()].size() > 1 || qu.front() == emp)) inq[qu.front()] = 0, qu.pop();
    assert(!qu.empty()); int ret = qu.front(); 
    return ret;
}
struct Query{
    int opt, x, y;
    Query(int o, int a, int b = 0){opt = o, x = a, y = b;}
    void print(){printf("%d %d ", opt, x); if(opt == 2) printf("%d\n", y); else puts("");}
};
vector<Query> ans;
void wsyakioi(){
    assert(!sz);
    while(!qu.empty()) qu.pop();
    scanf("%d%d%d", &n, &m, &k), ans.clear();
    for(int i = 1; i <= m; i++) scanf("%d", &a[i]);
    for(int i = 1; i < n; i++) qu.push(i), inq[i] = 1;
    emp = n, sp = 2 * n - 1, fill(bel + 1, bel + n * 2 + 1, 0);
    for(int i = 1; i <= m; i++) if(sz < n * 2 - 2 || cnt[a[i]]){
        if(!cnt[a[i]]) bel[a[i]] = front(), ans.pb(Query(1, bel[a[i]])), st[bel[a[i]]].pb(a[i]);
        else if(st[bel[a[i]]].back() == a[i]) ans.pb(Query(1, bel[a[i]])), st[bel[a[i]]].pb(a[i]);
        else if(st[bel[a[i]]].front() == a[i]) ans.pb(Query(1, emp)), ans.pb(Query(2, bel[a[i]], emp)), st[bel[a[i]]].ppf();
        else assert(0);
    }else{
        sp = a[i];
        int j = i + 1, qwq = 0;
        for(; j <= m; j++) if(bel[a[j]] && st[bel[a[j]]].size() == 2 && st[bel[a[j]]].front() == a[j]) break;
        if(j == m + 1){ans.pb(Query(1, emp)), st[emp].pb(a[i]), bel[a[i]] = emp; continue;}
        for(int k = i + 1; k <= j; k++) if(a[k] == st[bel[a[j]]].back()) qwq++;
        int ano = st[bel[a[j]]].back();
        if(qwq & 1){
            bel[sp] = emp, ans.pb(Query(1, emp)), st[emp].pb(a[i]);
            for(int k = i + 1; k <= j; k++) st[bel[a[k]]].pb(a[k]), ans.pb(Query(1, bel[a[k]]));
            assert(st[bel[a[j]]].empty()); 
            qu.push(emp), inq[emp] = 1;
            bel[a[j]] = emp, sp = ano, emp = bel[ano], bel[ano] = 0;
            i = j;
        }else{
            bel[sp] = bel[a[j]], bel[ano] = emp;
            for(int k = i; k < j; k++) st[bel[a[k]]].pb(a[k]), ans.pb(Query(1, bel[a[k]]));
            ans.pb(Query(1, emp)), ans.pb(Query(2, bel[a[j]], emp)), st[bel[a[j]]].ppf();
            assert(st[emp].empty());
            bel[ano] = bel[a[j]], sp = a[j], bel[sp] = 0;
            i = j;
        }
    }
    printf("%d\n", ans.size());
    for(auto p : ans) p.print();
    for(int i = 1; i <= n; i++) assert(st[i].empty());
}
int main(){
    for(int i = 1; i < maxn; i++) st[i].id = i;
    int T; scanf("%d", &T);
    while(T--) wsyakioi();
    return 0;
}